package com.sgb.kjwl.view.ui.fragment.enterprise;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentMakeoverMessageBinding;
import com.sgb.kjwl.view.ui.adapter.CommPagerAdapter3;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class MakeOverForMessageFragment extends AppFragment {

    private FragmentMakeoverMessageBinding mBinding;
    private String[] mTag = {"商标", "版权", "专利"};
    private ArrayList<Fragment> mList;
    private String websiteNo;
    private String websiteType;


    public static MakeOverForMessageFragment newInstance(String websiteNo, String websiteType) {
        MakeOverForMessageFragment fragment = new MakeOverForMessageFragment();
        Bundle args = new Bundle();
        args.putString("websiteNo", websiteNo);
        args.putString("websiteType", websiteType);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_makeover_message,container,false);
        return mBinding.getRoot();
    }


    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initview();
    }


    private void initview(){
        websiteNo = getArguments().getString("websiteNo");
        websiteType = getArguments().getString("websiteType");
        mList = new ArrayList<>();
        //商标、版权、专利、公司、资产
        String categoryMark = null, categoryCopyright = null, categoryPatent = null;

        IntellpropFragment intellpropFragment = IntellpropFragment.newInstance(0, categoryMark,websiteNo,websiteType);
        IntellpropFragment intellpropFragment2 = IntellpropFragment.newInstance(1, categoryCopyright,websiteNo,websiteType);
        IntellpropFragment intellpropFragment3 = IntellpropFragment.newInstance(2, categoryPatent,websiteNo,websiteType);
        mList.add(intellpropFragment);
        mList.add(intellpropFragment2);
        mList.add(intellpropFragment3);
        mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(MakeOverForMessageFragment.this.getActivity()).inflate(R.layout.item_lin_2, null);
                TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        mBinding.vpMakeOverMain.setAdapter(new CommPagerAdapter3(getChildFragmentManager(), mList, mTag) {
            @Override
            public Fragment getItem(int position) {
                return mList.get(position);
            }

            @Override
            public int getCount() {
                return mList.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return mTag[position];
            }
        });


        mBinding.tabLayout.setupWithViewPager(mBinding.vpMakeOverMain);
        mBinding.tabLayout.getTabAt(0).select();
        mBinding.vpMakeOverMain.setCurrentItem(0);

    }

}
